package com.jingsong.studentapp.adapter;
/*
 * @author zei , QQ:77132995, email:kazeik@163.com
 * 2021-12-18 10:53
 * 类说明:
 */

import android.annotation.SuppressLint;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.jingsong.studentapp.R;
import com.jingsong.studentapp.lister.OnItemEventListener;
import com.jingsong.studentapp.model.AppraisalModel;

public class AppraisalAdapter<A> extends BaseAdapter<A> {
    private OnItemEventListener eventListener;

    public void setEventListener(OnItemEventListener eventListener) {
        this.eventListener = eventListener;
    }


    @Override
    public int getLaoutView() {
        return R.layout.layout_appraisal_item;
    }

    @SuppressLint({"UseCompatLoadingForDrawables", "SetTextI18n"})
    @Override
    public void onBindViewHolder(@NonNull KBaseViewHolder holder, int position) {
        TextView tvApprStatus = (TextView) holder.getViewById(R.id.tvApprStatus);
        TextView tvApprTitle = (TextView) holder.getViewById(R.id.tvApprTitle);
        TextView tvScore = (TextView) holder.getViewById(R.id.tvScore);
        TextView tvAllScore = (TextView) holder.getViewById(R.id.tvAllScore);
        TextView tvTimes = (TextView) holder.getViewById(R.id.tvTimes);
        TextView tvCard = (TextView) holder.getViewById(R.id.tvCard);
        TextView tvApprColor = (TextView) holder.getViewById(R.id.tvApprColor);
        LinearLayout llScore = (LinearLayout) holder.getViewById(R.id.llScore);

        tvCard.setOnClickListener(view -> {
            if (null != eventListener) {
                eventListener.onItemEvent(position);
            }
        });

        AppraisalModel model = (AppraisalModel) getDatas().get(position);
//        tvApprStatus.setText(;
        tvApprTitle.setText(model.name);
        tvScore.setText("" + (model.minNum == 0.0f ? 0 : model.minNum));
        tvAllScore.setText("/" + model.max);
        tvTimes.setText("考试时间:" + model.times);

        switch (model.state) {
            case 0:
                tvApprStatus.setText("候考中");
                tvCard.setVisibility(View.INVISIBLE);
                llScore.setVisibility(View.GONE);
                tvApprColor.setBackground(holder.getContext().getResources().getDrawable(R.drawable.rount_green_shrap));
                tvApprStatus.setTextColor(holder.getContext().getResources().getColor(R.color.c24bb95));
                break;
            case 1:
                tvApprStatus.setText("考试已结束");
                tvCard.setVisibility(View.VISIBLE);
                tvCard.setBackground(holder.getContext().getResources().getDrawable(R.drawable.button_rount_empty_shrap));
                tvCard.setTextColor(holder.getContext().getResources().getColor(R.color.c24bb95));
                tvScore.setTextColor(holder.getContext().getResources().getColor(R.color.c24bb95));
                tvCard.setText("答题卡");
                tvApprColor.setBackground(holder.getContext().getResources().getDrawable(R.drawable.rount_grey_shrap));
                llScore.setVisibility(View.VISIBLE);
                break;
            case 2:
                tvApprStatus.setText("考试已结束");
                tvCard.setVisibility(View.VISIBLE);
                tvCard.setBackground(holder.getContext().getResources().getDrawable(R.drawable.button_rount_empty_grey_shrap));
                tvCard.setTextColor(holder.getContext().getResources().getColor(R.color.linegray_color1));
                tvCard.setText("缺考");
                llScore.setVisibility(View.VISIBLE);
                tvApprColor.setBackground(holder.getContext().getResources().getDrawable(R.drawable.rount_grey_shrap));
                break;
            case 3:
                tvApprStatus.setText("考试中");
                tvApprStatus.setTextColor(holder.getContext().getResources().getColor(R.color.c24bb95));
                llScore.setVisibility(View.GONE);
                tvCard.setText("开始");
                tvCard.setBackground(holder.getContext().getResources().getDrawable(R.drawable.button_rount_shrap));
                tvCard.setTextColor(holder.getContext().getResources().getColor(R.color.white));
                break;
        }
    }
}
